package com.ctrip.cap.client.mail;

import com.ctrip.cap.client.impl.base.BaseClient;
import com.ctrip.cap.client.impl.base.BaseClientImpl.HttpMethodType;
import com.ctrip.cap.domain.mail.SendMailParam;

public class MailServiceClient extends BaseClient {
	private final static String BASE_PATH = "/mail/service";
	private final static String SEND_MAIL = "/send";
	
	public MailServiceClient() {
		baseUrl = "http://localhost:8080/cap-data-server";
	}
	
	public MailServiceClient(String jenkinsServer) {
		baseUrl = jenkinsServer;
	}
	
	public int sendMail(SendMailParam mailParam) {
		return this.baseCall(BASE_PATH+SEND_MAIL, mailParam , HttpMethodType.POST, Integer.class);
	}
	
	public int sendMailToAutotest(String subject, String content) {
		SendMailParam mailParam = new SendMailParam();
		mailParam.setReceviver(new String[]{"autotest@ctrip.com"});
		mailParam.setMessage(content);
		mailParam.setTitle(subject);
		return sendMail(mailParam);
	}
	
	public static void main(String[] args) {
		SendMailParam mailParam = new SendMailParam();
		String contentString = "<img width=500 height=500 src=\"http://192.168.43.211/picture/43f1f6fd-5f83-49f6-b104-ad5a33a024b9.png\"/>";
		String[] receiver = new String[]{"sun.liang@ctrip.com"};
		mailParam.setReceviver(receiver);
		mailParam.setMessage(contentString);
		mailParam.setTitle("Test");
		MailServiceClient mailClient = new MailServiceClient("http://ciapi.dev.sh.ctripcorp.com:8080/cap-data");
		mailClient.sendMail(mailParam);
	}
}
